import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—07—11
 * Time: 14:21
 */
class Card {
    public int rank;//点数
    public String suit;//花色

    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    @Override
    public String toString() {
        return suit+" "+rank;
    }
}
public class CardDemo {
    public static final String [] suits = {"♥", "♠", "♣", "♦"};

    //拿一副牌出来
    public List<Card> buyDeskCard() {
        List<Card> cards = new ArrayList<>();
        for (int i = 1; i <= 13; i++) {
            for (int j = 0; j < 4; j++) {
                Card card = new Card(i,suits[j]);
                cards.add(card);
            }
        }
        return cards;
    }
    //洗牌
    public void shuffle(List<Card> cards) {

        for (int i = cards.size()-1; i > 0; i--) {
            //产生随机数
            Random random = new Random();
            int index = random.nextInt(i);
            //交换
            swap(cards,index,i);
        }
    }
    //交换
    private void swap(List<Card> cards, int i, int j) {
        Card tmp = cards.get(i);
        cards.set(i,cards.get(j));
        cards.set(j,tmp);
    }
    //发牌了
    public List<List<Card>> test(List<Card> cards) {
        //new三个人出来
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        List<List<Card>> hands = new ArrayList<>();
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);
        //轮流拿五张牌
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cards.remove(0);
                hands.get(j).add(card);
            }
        }
        return hands;
    }
}
